public class MapService {
    private final RedisRepository redisRepo;

    public MapService(RedisRepository redisRepo) {
        this.redisRepo = redisRepo;
    }

    public boolean isObstacle(int x, int y, RedisRepository.MapData data) {
        if (x < 0 || y < 0 || x >= data.width || y >= data.height) return false;

        long offset = (long) y * data.width + x;
        if (offset >= data.obstaclesStr.length()) return false;

        return data.obstaclesStr.charAt((int) offset) == '1';
    }

    public boolean isLighted(int x, int y, RedisRepository.MapData data) {
        if (x < 0 || y < 0 || x >= data.width || y >= data.height) return false;

        long offset = (long) y * data.width + x;
        if (offset >= data.lightsStr.length()) return false;

        return data.lightsStr.charAt((int) offset) == '1';
    }


    public RedisRepository.MapData getCurrentMapData() {
        return redisRepo.getMapData();
    }


}
